package org.groupg.filetodb.model.database;


import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

import java.io.Serializable;

/**
 * 表示数据库支持的数据类型信息
 */
public class TypeInfo implements Serializable {
    /**
     * 类型名称
     */
    private String typeName;
    /**
     * SQL类型 (java.sql.Types)
     */
    private int dataType;
    /**
     * 最大精度
     */
    private int precision;
    /**
     * 字面值前缀（如字符串的'）
     */
    private String literalPrefix;
    /**
     * 字面值后缀
     */
    private String literalSuffix;
    /**
     * 创建参数（如精度和小数位）
     */
    private String createParams;
    /**
     * 是否允许NULL
     */
    private int nullable;
    /**
     * 是否区分大小写
     */
    private boolean caseSensitive;
    /**
     * 是否可用于WHERE子句
     */
    private short searchable;
    /**
     * 是否为无符号类型
     */
    private boolean unsigned;
    /**
     * 是否固定精度/小数位
     */
    private boolean fixedPrecScale;
    /**
     * 是否可用于自增
     */
    private boolean autoIncrement;
    /**
     * 本地化类型名
     */
    private String localTypeName;
    /**
     * 最小小数位
     */
    private short minScale;
    /**
     * 最大小数位
     */
    private short maxScale;
    /**
     * 基数（通常为2或10）
     */
    private int numPrecRadix;

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("typeName", typeName)
                .add("dataType", dataType)
                .add("precision", precision)
                .add("literalPrefix", literalPrefix)
                .add("literalSuffix", literalSuffix)
                .add("createParams", createParams)
                .add("nullable", nullable)
                .add("caseSensitive", caseSensitive)
                .add("searchable", searchable)
                .add("unsigned", unsigned)
                .add("fixedPrecScale", fixedPrecScale)
                .add("autoIncrement", autoIncrement)
                .add("localTypeName", localTypeName)
                .add("minScale", minScale)
                .add("maxScale", maxScale)
                .add("numPrecRadix", numPrecRadix)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        TypeInfo typeInfo = (TypeInfo) o;
        return getDataType() == typeInfo.getDataType() && getPrecision() == typeInfo.getPrecision() && getNullable() == typeInfo.getNullable() && isCaseSensitive() == typeInfo.isCaseSensitive() && getSearchable() == typeInfo.getSearchable() && isUnsigned() == typeInfo.isUnsigned() && isFixedPrecScale() == typeInfo.isFixedPrecScale() && isAutoIncrement() == typeInfo.isAutoIncrement() && getMinScale() == typeInfo.getMinScale() && getMaxScale() == typeInfo.getMaxScale() && getNumPrecRadix() == typeInfo.getNumPrecRadix() && Objects.equal(getTypeName(), typeInfo.getTypeName()) && Objects.equal(getLiteralPrefix(), typeInfo.getLiteralPrefix()) && Objects.equal(getLiteralSuffix(), typeInfo.getLiteralSuffix()) && Objects.equal(getCreateParams(), typeInfo.getCreateParams()) && Objects.equal(getLocalTypeName(), typeInfo.getLocalTypeName());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getTypeName(), getDataType(), getPrecision(), getLiteralPrefix(), getLiteralSuffix(), getCreateParams(), getNullable(), isCaseSensitive(), getSearchable(), isUnsigned(), isFixedPrecScale(), isAutoIncrement(), getLocalTypeName(), getMinScale(), getMaxScale(), getNumPrecRadix());
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public int getDataType() {
        return dataType;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public int getPrecision() {
        return precision;
    }

    public void setPrecision(int precision) {
        this.precision = precision;
    }

    public String getLiteralPrefix() {
        return literalPrefix;
    }

    public void setLiteralPrefix(String literalPrefix) {
        this.literalPrefix = literalPrefix;
    }

    public String getLiteralSuffix() {
        return literalSuffix;
    }

    public void setLiteralSuffix(String literalSuffix) {
        this.literalSuffix = literalSuffix;
    }

    public String getCreateParams() {
        return createParams;
    }

    public void setCreateParams(String createParams) {
        this.createParams = createParams;
    }

    public int getNullable() {
        return nullable;
    }

    public void setNullable(int nullable) {
        this.nullable = nullable;
    }

    public boolean isCaseSensitive() {
        return caseSensitive;
    }

    public void setCaseSensitive(boolean caseSensitive) {
        this.caseSensitive = caseSensitive;
    }

    public short getSearchable() {
        return searchable;
    }

    public void setSearchable(short searchable) {
        this.searchable = searchable;
    }

    public boolean isUnsigned() {
        return unsigned;
    }

    public void setUnsigned(boolean unsigned) {
        this.unsigned = unsigned;
    }

    public boolean isFixedPrecScale() {
        return fixedPrecScale;
    }

    public void setFixedPrecScale(boolean fixedPrecScale) {
        this.fixedPrecScale = fixedPrecScale;
    }

    public boolean isAutoIncrement() {
        return autoIncrement;
    }

    public void setAutoIncrement(boolean autoIncrement) {
        this.autoIncrement = autoIncrement;
    }

    public String getLocalTypeName() {
        return localTypeName;
    }

    public void setLocalTypeName(String localTypeName) {
        this.localTypeName = localTypeName;
    }

    public short getMinScale() {
        return minScale;
    }

    public void setMinScale(short minScale) {
        this.minScale = minScale;
    }

    public short getMaxScale() {
        return maxScale;
    }

    public void setMaxScale(short maxScale) {
        this.maxScale = maxScale;
    }

    public int getNumPrecRadix() {
        return numPrecRadix;
    }

    public void setNumPrecRadix(int numPrecRadix) {
        this.numPrecRadix = numPrecRadix;
    }

    // 省略getter/setter
}